home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14006 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  53 lines

  1. Path: swidir.switch.ch!epflnews!Thomas.Wolf
  2. From: Thomas.Wolf@di.epfl.ch (Thomas Wolf)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help
  5. Date: 11 Apr 1996 08:00:34 GMT
  6. Organization: Ecole Polytechnique FΘdΘrale de Lausanne
  7. Sender: wolf@lglsun5.epfl.ch (Thomas Wolf)
  8. Message-ID: <4kie72$djg@info.epfl.ch>
  9. References: <316C3043.A5D@hlp.com>
  10. NNTP-Posting-Host: lglsun5.epfl.ch
  11.  
  12. In article <316C3043.A5D@hlp.com>, andrew kennedy <"andrew kennedy"@hlp.com> writes:
  13. :> 
  14. :> I wrote this code early in my C career, but there should be a better to
  15. :> do this. Can someone help.
  16. :> 
  17. [Snip]
  18.  
  19. Although it's not hard to figure out, it would have been nice if you'd
  20. given a short description of what your code was supposed to do.
  21.  
  22. Anyway, look up the 'strrchr' function in the standard library. Using
  23. it greatly simplifies your task:
  24.  
  25.   #include <string.h>
  26.   
  27.   ...
  28.   
  29.   void set_suffix (char *original, char *suffix, char *new)
  30.   {
  31.     char *p;
  32.   
  33.     strcpy (new, original);
  34.     p = strrchr (new, '.');
  35.     if (p && p != new) *p = '\0';
  36.     strcat (new, suffix);
  37.   }
  38.   
  39. (The "p != new" part handles cases like ".cshrc" correctly - I suppose
  40.  you'd want such a file name to become ".cshrc.enc", not ".enc"...
  41.  The 'suffix' is supposed to start with a dot.)
  42.  
  43. Regards,
  44.  
  45.   Thomas
  46. ----------------------------------------------------------------------
  47. Swiss Federal Institute of Technology | Thomas Wolf
  48. Software Engineering Laboratory       | EPFL-DI-LGL
  49. Thomas Wolf (TW)                      | CH-1015 Lausanne (Suisse)
  50. E-Mail: wolf@di.epfl.ch               | Phone: (++41 21)693 42 37
  51. ---------------------------------------------------------------------- 
  52.  
  53.